<?php
/**
 * Description:
 * Author: hezhizheng
 * Date: 2018/11/15
 * Time: 12:25
 * Created by Created by Panxsoft.
 */

namespace App\Services\Customers\Register;


use App\Exceptions\ApiErrCode;
use App\Exceptions\ApiException;
use App\Models\Customers\Customer;

class RegisterFactory
{
    /**
     * @param string $type
     * @return EmailRegisterService|TelephoneRegisterService
     * @throws ApiException
     * @throws \App\Exceptions\ApiSilentException
     */
    public static function create(string $type)
    {
        switch ($type) {
            case Customer::REGISTER_TYPE_EMAIL;
                return  new EmailRegisterService;
                break;
            case Customer::REGISTER_TYPE_TELEPHONE;
                return  new TelephoneRegisterService;
                break;
            default:
                throw new ApiException(ApiErrCode::CUSTOMIZE_ERROR, 'error register type');
        }
    }
}